(function (G) {
    G.vue({
        data: {
            allCase: [],
            baseUrl: G.Storage.get("APIURL"),
            backIcon: G.Storage.get("APIURL") + '/file/1599419804094173184',
            jiaIcon: G.Storage.get("APIURL") + '/file/1599421254895538176',
            deleteIcon: G.Storage.get("APIURL") + '/file/1599421740252008448',
        },
        methods: {
            startNow(e) {
                let that = this
                G.put('/api/model/g_emergency_plan', {
                    id: that.data.allCase[e.currentTarget.dataset.index].id,
                    status: 2
                }).then(res => {
                    if (!res.errorMsg) {
                        G.post('/v1/task/add', {
                            userId: G.Storage.get('userInfo').id,
                            flowId: that.data.allCase[e.currentTarget.dataset.index].f_flowId,
                            data: that.data.allCase[e.currentTarget.dataset.index],
                            title: that.data.allCase[e.currentTarget.dataset.index].preName,
                            toUsers: that.data.allCase[e.currentTarget.dataset.index].userId
                        }).then(res1 => {
                            if (!res1.errorMsg) {
                                G.put('/api/model/g_emergency_plan', {
                                    id: that.data.allCase[e.currentTarget.dataset.index].id,
                                    taskID: res1.task.id
                                }).then(res2 => {
                                    if (!res2.errorMsg) {
                                        wx.showToast({
                                            title: '启用成功',
                                            icon: 'success'
                                        })
                                        that.getData1()
                                    }
                                })
                            }
                        })
                    }
                })
            },
            deleteIcon(e) {
                let that = this
                console.log('---e', e.currentTarget.dataset.index);
                wx.showModal({
                    title: '提示',
                    content: '确定删除此预案？',
                    success (res) {
                      if (res.confirm) {
                        G.delete('/api/model/g_emergency_plan', {
                            id: that.data.allCase[e.currentTarget.dataset.index].id
                        }).then(res => {
                            if (!res.errorMsg) {
                                console.log('---res', res);
                                that.getData1()
                            }
                        })
                      } else if (res.cancel) {
                        console.log('用户点击取消')
                      }
                    }
                  })
            },
            toDetail() {
                let that = this
                wx.navigateTo({
                    url: '/pages/gypatrol/emerg/detail',
                    events: {
                        getNewData: function (data) {
                            that.getData1()
                        }
                    },
                })
            },
            getData1() {
                let that = this
                G.get('/api/model/g_emergency_plan', {
                    userId:G.Storage.get('userInfo').id,
                    sql: {
                        join: {
                            f_flowId: {
                                type: 'LEFT',
                                name: 'f_flow',
                                key: 'id',
                                projection: {
                                    name: 'f_flowName'
                                }
                            },
                            userId: {
                                type: 'LEFT',
                                name: 'user',
                                key: 'id',
                                projection: {
                                    name: 'userName'
                                }
                            }
                        }
                    }
                }).then(res => {
                    console.log('----re', res);
                    if (!res.errorMsg) {
                        console.log(res);
                        that.setData({
                            allCase: res
                        })
                    }
                })
            },

        },
        mounted() {
            this.getData1()
        }
    })
})(wx.$)